import {
    playerStore,
    rankingStore
} from '../../store/index'
import {
    getSongMenuDetail
} from '../../service/music-api'

Page({
    data: {
        type: "",
        ranking: "",
        songInfo: {}
    },
    onLoad: function (options) {
        const type = options.type
        this.setData({
            type
        })

        if (type === "menu") {
            const id = options.id
            getSongMenuDetail(id).then(res => {
                this.setData({
                    songInfo: res.playlist
                })
            })
        } else if (type === "rank") {
            const ranking = options.ranking
            this.setData({
                ranking
            })

            // 1.获取数据
            rankingStore.onState(ranking, this.getRankingDataHanlder)
        }
    },

    getRankingDataHanlder: function (res) {
        this.setData({
            songInfo: res
        })
    },

    handleSongItemClick: function(event) {
        const index = event.currentTarget.dataset.index
        playerStore.setState("playListSongs", this.data.songInfo.tracks)
        playerStore.setState("playListIndex", index)
    },
})